package fb4java.beans;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class NotificationStatus {
    public int msgUnread;
    public long msgMostRecent;
    public int pokesUnread;
    public long pokesMostRecent;
    public int shareUnread;
    public long shareMostUnread;

    public long[] friendRequests;
    public long[] groupInvites;
    public long[] eventInvites;

    public NotificationStatus() {
    }

    public NotificationStatus(JSONObject obj) throws JSONException {
        initByJSONObject(obj);
    }

    public void initByJSONObject(JSONObject obj) throws JSONException {
        JSONObject messages = obj.getJSONObject("messages");
        msgUnread = messages.getInt("unread");
        msgMostRecent = messages.getLong("most_recent");

        JSONObject pokes = obj.getJSONObject("pokes");
        pokesUnread = pokes.getInt("unread");
        pokesMostRecent = pokes.getLong("most_recent");

        JSONObject shares = obj.getJSONObject("pokes");
        shareUnread = pokes.getInt("unread");
        shareMostUnread = pokes.getLong("most_recent");

        JSONArray friends = obj.getJSONArray("friend_requests");
        friendRequests = new long[friends.length()];
        for (int a = 0; a < friendRequests.length; a++) {
            friendRequests[a] = friends.getLong(a);
        }

        JSONArray groups = obj.getJSONArray("group_invites");
        groupInvites = new long[groups.length()];
        for (int a = 0; a < friendRequests.length; a++) {
            groupInvites[a] = groups.getLong(a);
        }

        JSONArray events = obj.getJSONArray("event_invites");
        eventInvites = new long[events.length()];
        for (int a = 0; a < friendRequests.length; a++) {
            eventInvites[a] = events.getLong(a);
        }
    }
}
